<?php

/**
 * Groupe filter form base class.
 *
 * @package    tfe
 * @subpackage filter
 * @author     3emeIG
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseGroupeFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'libelle'                              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'type'                                 => new sfWidgetFormChoice(array('choices' => array('' => '', 'Famille' => 'Famille', 'Entreprise' => 'Entreprise', 'Presse' => 'Presse', 'Fournisseurs' => 'Fournisseurs', 'Scolaire' => 'Scolaire', 'Troupe' => 'Troupe', 'Autre' => 'Autre'))),
      'responsable'                          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Responsable'), 'add_empty' => true)),
      'telephone'                            => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'mail'                                 => new sfWidgetFormFilterInput(),
      'envoyer_news_par_mail'                => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'envoyer_news_par_lettre'              => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'commentaire'                          => new sfWidgetFormFilterInput(),
      'deleted_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'created_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'membres_list'                         => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Contact')),
      'courriers_electroniques_envoyes_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'CourrierElectronique')),
    ));

    $this->setValidators(array(
      'libelle'                              => new sfValidatorPass(array('required' => false)),
      'type'                                 => new sfValidatorChoice(array('required' => false, 'choices' => array('Famille' => 'Famille', 'Entreprise' => 'Entreprise', 'Presse' => 'Presse', 'Fournisseurs' => 'Fournisseurs', 'Scolaire' => 'Scolaire', 'Troupe' => 'Troupe', 'Autre' => 'Autre'))),
      'responsable'                          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Responsable'), 'column' => 'id')),
      'telephone'                            => new sfValidatorPass(array('required' => false)),
      'mail'                                 => new sfValidatorPass(array('required' => false)),
      'envoyer_news_par_mail'                => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'envoyer_news_par_lettre'              => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'commentaire'                          => new sfValidatorPass(array('required' => false)),
      'deleted_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'created_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'membres_list'                         => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Contact', 'required' => false)),
      'courriers_electroniques_envoyes_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'CourrierElectronique', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('groupe_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addMembresListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.MembreGroupe MembreGroupe')
          ->andWhereIn('MembreGroupe.id_contact', $values);
  }

  public function addCourriersElectroniquesEnvoyesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.GroupeDestinataire GroupeDestinataire')
          ->andWhereIn('GroupeDestinataire.id_courrier_electronique', $values);
  }

  public function getModelName()
  {
    return 'Groupe';
  }

  public function getFields()
  {
    return array(
      'id'                                   => 'Number',
      'libelle'                              => 'Text',
      'type'                                 => 'Enum',
      'responsable'                          => 'ForeignKey',
      'telephone'                            => 'Text',
      'mail'                                 => 'Text',
      'envoyer_news_par_mail'                => 'Boolean',
      'envoyer_news_par_lettre'              => 'Boolean',
      'commentaire'                          => 'Text',
      'deleted_at'                           => 'Date',
      'created_at'                           => 'Date',
      'updated_at'                           => 'Date',
      'membres_list'                         => 'ManyKey',
      'courriers_electroniques_envoyes_list' => 'ManyKey',
    );
  }
}
